import {DocumentBuilder, SwaggerModule} from "@nestjs/swagger";
import {NestExpressApplication} from "@nestjs/platform-express";
import {SwaggerOptions} from "@app/common/types/swagger";

export function setupSwagger(app: NestExpressApplication, swaggerOptions: SwaggerOptions) {
  const options = new DocumentBuilder()
      .setTitle(swaggerOptions.title) // 标题
      .setDescription(swaggerOptions.description) // 描述
      .setVersion(swaggerOptions.version) // 版本
      .addBearerAuth()
      .build();

  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup(swaggerOptions.path, app, document);
}
